package com.aegean.MonitorExamSYS.conduction.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExaxSYS.model.CenterValue;
import com.aegean.MonitorExaxSYS.model.ConductionValue;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("ShowConductionImage")
@Scope("prototype")
public class ShowConductionImage extends ActionSupport{
	private ConductionValue conduction;
	InputStream user_Photo;
	String photoName;
	String photoType;

	public InputStream getUser_Photo() {
		return user_Photo;
	}

	public void setUser_Photo(InputStream user_Photo) {
		this.user_Photo = user_Photo;
	}

	public String getPhotoName() {
		return photoName;
	}

	public void setPhotoName(String photoName) {
		this.photoName = photoName;
	}

	public String getPhotoType() {
		return photoType;
	}

	public void setPhotoType(String photoType) {
		this.photoType = photoType;
	}

	public InputStream getDownload() {
		try {
			HttpSession session = (HttpSession) ServletActionContext
					.getRequest().getSession();
			conduction = (ConductionValue) session.getAttribute("ConductionLogin");
				String root = ServletActionContext.getServletContext().getRealPath(
						"/dateFile/conduction/" + conduction.getConduction_Name());
				File photo = new File(root + "/" + conduction.getConduction_Photo().getPhoto_Name());
				InputStream in = new FileInputStream(photo);
				return in;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
}
